<!--
  User: Kuttubek Aidaraliev
  Date: 06.04.2010
  Time: 16:13:37
-->
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    template="../../WEB-INF/jspx/common/template.xhtml">
  <ui:define name="head">
      <title>
          <h:outputText value="#{messages.creatingCustomer}" rendered="#{customerBean.newEntity}"/>
          <h:outputText value="#{messages.editingCustomer}" rendered="#{!customerBean.newEntity}"/>
      </title>
  </ui:define>
  <ui:define name="body">
        
        <a4j:outputPanel ajaxRendered="true">
            <ui:include src="../../WEB-INF/jspx/region/region.xhtml"/>
        </a4j:outputPanel>

        <h:panelGroup rendered="#{customerBean.newEntity}">
            <h3 align="center"><h:outputText value="#{messages.creatingCustomer}" /></h3>
        </h:panelGroup>
        <h:panelGroup rendered="#{!customerBean.newEntity}">
            <h3 align="center"><h:outputText value="#{customerBean.entity.officialName}" /></h3>
        </h:panelGroup>
        <h:form id="customerForm">

            <h:panelGroup>
                <a4j:region selfRendered="true">
                    <ui:include src="../../WEB-INF/jspx/customer/overview.xhtml"/>
                    <a4j:commandButton value="#{messages.update}" action="#{customerBeanController.updated}"
                             rendered="#{!customerBean.newEntity and customerBean.requisiteEditing}"/>
                    <rich:spacer width="10" rendered="#{!customerBean.newEntity and customerBean.requisiteEditing}"/>
                    <a4j:commandButton value="#{messages.cancel}" onclick="executeAction('customerForm:overviewCancelAction')"
                             rendered="#{!customerBean.newEntity and customerBean.requisiteEditing}"/>
                    <a4j:htmlCommandLink id="overviewCancelAction" value="" action="#{customerBeanController.cancel}"
                             rendered="#{!customerBean.newEntity and customerBean.requisiteEditing}">
                        <f:setPropertyActionListener value="false" target="#{customerBean.requisiteEditing}"/>
                    </a4j:htmlCommandLink>
                    <a4j:commandButton rendered="#{!customerBean.newEntity and not customerBean.requisiteEditing}"
                             immediate="true" value="#{messages.edit}" onclick="executeAction('customerForm:overviewEditAction')"/>
                    <a4j:htmlCommandLink id="overviewEditAction" value="" action="#{customerBeanController.currentPage}"
                             rendered="#{!customerBean.newEntity and not customerBean.requisiteEditing}"
                             immediate="true">
                        <f:setPropertyActionListener value="true" target="#{customerBean.requisiteEditing}"/>
                    </a4j:htmlCommandLink>
                  </a4j:region>
            </h:panelGroup>

            <rich:spacer height="15" width="100%"/>

             <rich:tabPanel switchType="ajax" binding="#{customerBean.contactPersonTabPanel}"
                            height="400px" width="80%" rendered="#{!customerBean.newEntity}" style="tabPanelClass">
                <!--<rich:tab label="#{messages.overview}">
                  <a4j:region>
                    <ui:include src="layout/customer/overview.xhtml"/>
                    <a4j:commandButton value="#{messages.update}" action="#{customerBeanController.updated}"
                             rendered="#{!customerBean.newEntity and customerRequestBeanController.editField}"/>
                    <rich:spacer width="10" rendered="#{!customerBeanController.newEntity and customerRequestBeanController.editField}"/>
                    <a4j:commandButton value="#{messages.cancel}" action="#{customerBeanController.cancel}"
                             rendered="#{!customerBeanController.newEntity and customerRequestBeanController.editField}"/>
                    <a4j:commandButton rendered="#{!customerBeanController.newEntity and not customerRequestBeanController.editField}"
                             immediate="true" value="#{messages.edit}" onclick="executeAction('customerForm:overviewEditAction')"/>
                    <a4j:htmlCommandLink id="overviewEditAction" value="" action="#{customerBeanController.preUpdate}"
                             rendered="#{!customerBeanController.newEntity and not customerRequestBeanController.editField}"
                             immediate="true"/>
                  </a4j:region>

                </rich:tab>-->
                <rich:tab label="#{messages.requisite}" id="requisiteTab">
                  <a4j:region selfRendered="true">
                    <h:panelGrid columns="2">
                        <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.legalAddress}                       " id="legalAddressLabel" /></ui:define>
                            <h:inputText id="legalAddress" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.legalAddress}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="true"/>
                            <ui:param name="idInput" value="legalAddress"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.legalAddress}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.iin}" id="iinLabel" /></ui:define>
                            <h:inputText id="iin" required="false" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.iin}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="iin"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.iin}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.kpp}" id="kppLabel" /></ui:define>
                            <h:inputText id="kpp" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.kpp}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="kpp"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.kpp}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.accountNumber}" id="accountNumberLabel" /></ui:define>
                            <h:inputText id="accountNumber" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.accountNumber}" validatorMessage="#{messages.valueNotNumber}"
                                rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="accountNumber"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.accountNumber}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.bankName}" id="bankNameLabel" /></ui:define>
                            <h:inputText id="bankName" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.bankName}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="bankName"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.bankName}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.bankIdCode}" id="bankIdCodeLabel" /></ui:define>
                            <h:inputText id="bankIdCode" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.bankIdCode}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="bankIdCode"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.bankIdCode}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.correspondentAccount}" id="correspondentAccountLabel" /></ui:define>
                            <h:inputText id="correspondentAccount" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.correspondentAccount}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="correspondentAccount"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.correspondentAccount}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.supervisor}" id="supervisorLabel" /></ui:define>
                            <h:inputText id="supervisor" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.supervisor}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="supervisor"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.supervisor}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.supervisorPosition}" id="supervisorPositionLabel" /></ui:define>
                            <h:inputText id="supervisorPosition" required="true" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.supervisorPosition}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="supervisorPosition"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.supervisorPosition}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>

                   <ui:decorate template="../../WEB-INF/jspx/common/edit.xhtml">
                            <ui:define name="label"><h:outputText value="#{messages.chiefAccountant}" id="chiefAccountantLabel" /></ui:define>
                            <h:inputText id="chiefAccountant" required="false" requiredMessage="#{messages.requiedMessage}"
                                value="#{customerBean.entity.requisite.chiefAccountant}" rendered="#{customerBean.editField}"/>
                            <ui:param name="required" value="false"/>
                            <ui:param name="idInput" value="chiefAccountant"/>
                            <ui:param name="value" value="#{customerBean.entity.requisite.chiefAccountant}"/>
                            <ui:param name="editField" value="#{customerBean.editField}"/>
                   </ui:decorate>
                  </h:panelGrid>

                    <a4j:commandButton value="#{messages.update}" action="#{customerBeanController.updated}"
                             rendered="#{!customerBean.newEntity and customerBean.editField}"/>
                    <rich:spacer width="10" rendered="#{!customerBean.newEntity and customerBean.editField}"/>
                    <a4j:commandButton value="#{messages.cancel}" onclick="executeAction('customerForm:requisiteCancelAction')"
                             rendered="#{!customerBean.newEntity and customerBean.editField}">
                    </a4j:commandButton>
                    <a4j:htmlCommandLink id="requisiteCancelAction" value="" action="#{customerBeanController.cancel}"
                             rendered="#{!customerBean.newEntity and customerBean.editField}">
                        <f:setPropertyActionListener value="false" target="#{customerBean.editField}"/>
                    </a4j:htmlCommandLink>
                    <a4j:commandButton rendered="#{!customerBean.newEntity and not customerBean.editField}"
                             immediate="true" value="#{messages.edit}" onclick="executeAction('customerForm:requisiteEditAction')">
                    </a4j:commandButton>
                    <a4j:htmlCommandLink id="requisiteEditAction" value="" action="#{customerBeanController.preUpdate}"
                             rendered="#{!customerBean.newEntity and not customerBean.editField}"
                             immediate="true">
                        <f:setPropertyActionListener value="true" target="#{customerBean.editField}"/>
                    </a4j:htmlCommandLink>
                                        
                  </a4j:region>
                </rich:tab>
                <rich:tab label="#{messages.contactPersonList}" actionListener="#{customerBeanController.tabSelectedActionListener}">

                    <a4j:region>
                        <a4j:commandButton value="#{messages.add}" ajaxSingle="true"
                                           action="#{contactPersonBeanController.preInsert}">
                            <f:setPropertyActionListener value="true" target="#{customerBean.showFormContactPerson}"/>
                            <f:setPropertyActionListener value="true" target="#{contactPersonBeanController.returnNull}"/>
                        </a4j:commandButton>
                    </a4j:region>

                    <a4j:region>
                        <a4j:commandLink value="" ajaxSingle="true" action="#{customerBeanController.loadWithContactPersons}"
                                         reRender="contactPersonTable" id="updateContactPersonsLink"/>
                    </a4j:region>

                       <f:subview id="operation">
                       <ui:decorate template="../../WEB-INF/jspx/contactPerson/contactPersonTable.xhtml">
                            <a4j:region>
                                <a4j:form>
                                    <a4j:commandLink value="#{messages.view}" action="#{contactPersonBeanController.preView}">
                                        <f:setPropertyActionListener value="true" target="#{customerBean.showFormContactPerson}"/>
                                        <f:setPropertyActionListener value="true" target="#{contactPersonBeanController.returnNull}"/>
                                        <f:setPropertyActionListener value="#{contactPerson}" target="#{contactPersonBeanController.entity}"/>
                                    </a4j:commandLink>
                                    <rich:spacer width="15"/>
                                    <a4j:commandLink value="#{messages.edit}" action="#{contactPersonBeanController.preUpdate}">
                                        <f:setPropertyActionListener value="true" target="#{customerBean.showFormContactPerson}"/>
                                        <f:setPropertyActionListener value="true" target="#{contactPersonBeanController.returnNull}"/>
                                        <f:setPropertyActionListener value="#{contactPerson}" target="#{contactPersonBeanController.entity}"/>
                                    </a4j:commandLink>
                                    <rich:spacer width="15"/>
                                    <a4j:commandLink value="#{messages.delete}" id="delete" action="#{contactPersonBeanController.deleted}"
                                                     oncomplete="executeAction('customerForm:updateContactPersonsLink')">
                                        <f:setPropertyActionListener value="true" target="#{contactPersonBeanController.returnNull}"/>
                                        <f:setPropertyActionListener value="#{contactPerson}"
                                                target="#{contactPersonBeanController.entity}" />
                                    </a4j:commandLink>
                                </a4j:form>
                             </a4j:region>

                            <ui:param name="contactPersons" value="#{customerBean.entity.contactPersons}"/>
                            <ui:param name="id" value="contactPersonTable"/>

                        </ui:decorate>
                        </f:subview>

                    <a4j:outputPanel ajaxRendered="#{customerBean.changeContactPersons}">
                        <a4j:commandButton rendered="#{customerBean.changeContactPersons}" value="#{messages.update}"
                                           action="#{customerBeanController.updated}"/>
                    </a4j:outputPanel>

                    <a4j:outputPanel ajaxRendered="true">
                        <f:subview id="contactPersons">
                        <a4j:region>
                        <h:panelGroup rendered="#{customerBean.showFormContactPerson}" id="contactPersonForm">
                            <ui:decorate template="../../WEB-INF/jspx/contactPerson/form.xhtml">
                                <ui:define name="buttons">
                                    <a4j:commandButton value="#{messages.create}" id="create" action="#{contactPersonBeanController.inserted}"
                                        rendered="#{contactPersonBeanController.newEntity}" oncomplete="executeAction('customerForm:updateContactPersonsLink')">
                                        <f:setPropertyActionListener value="false" target="#{customerBean.showFormContactPerson}"/>
                                        <f:setPropertyActionListener value="true" target="#{contactPersonBeanController.returnNull}"/>
                                        <f:setPropertyActionListener value="#{customerBean.entity}" target="#{contactPersonBeanController.entity.customer}"/>
                                    </a4j:commandButton>
                                     <a4j:commandButton value="#{messages.cancel}" id="cancel" action="#{contactPersonBeanController.cancel}"
                                        rendered="#{contactPersonBeanController.newEntity}" ajaxSingle="true">
                                        <f:setPropertyActionListener value="false" target="#{customerBean.showFormContactPerson}"/>
                                        <f:setPropertyActionListener value="true" target="#{contactPersonBeanController.returnNull}"/>
                                    </a4j:commandButton>
                                    <a4j:commandButton value="#{contactPersonBeanController.editField ? messages.update : messages.cancel}" id="#{messages.update}" action="#{contactPersonBeanController.updated}"
                                        rendered="#{!contactPersonBeanController.newEntity}" oncomplete="executeAction('customerForm:updateContactPersonsLink')">
                                        <f:setPropertyActionListener value="false" target="#{customerBean.showFormContactPerson}"/>
                                        <f:setPropertyActionListener value="true" target="#{contactPersonBeanController.returnNull}"/>
                                        <f:setPropertyActionListener value="#{customerBean.entity}" target="#{contactPersonBeanController.entity.customer}"/>
                                    </a4j:commandButton>
                                </ui:define>
                            </ui:decorate>
                        </h:panelGroup>
                        </a4j:region>
                        </f:subview>
                    </a4j:outputPanel>

                </rich:tab>
             </rich:tabPanel>

        </h:form>
  </ui:define>
</ui:composition>